<template>
  <div>
    <el-button icon="el-icon-back" circle @click="back"></el-button>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="机构编号">
        <el-input v-model="form.jid"></el-input>
      </el-form-item>
      <el-form-item label="用户名称">
        <el-input v-model="form.username"></el-input>
      </el-form-item>
      <el-form-item label="用户密码">
        <el-input v-model="form.password"></el-input>
      </el-form-item>
      <el-form-item label="真实姓名">
        <el-input v-model="form.truename"></el-input>
      </el-form-item>
      <el-form-item label="身份证号">
        <el-input v-model="form.idcardNumber"></el-input>
      </el-form-item>
      <el-form-item label="用户权限">
        <el-select v-model="form.authority" placeholder="请选择权限类型">
          <el-option label="高" value="高"></el-option>
          <el-option label="中" value="中"></el-option>
          <el-option label="低" value="低"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="用户身份">
        <el-select v-model="form.identity" placeholder="请选择身份类型">
          <el-option label="消防人员" value="消防员"></el-option>
          <el-option label="司法人员" value="司法人员"></el-option>
          <el-option label="技术服务人员" value="技术服务人员"></el-option>
          <el-option label="鉴定机构人员" value="鉴定机构人员"></el-option>
          <el-option label="系统管理员" value="系统管理员"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="upd">确定添加</el-button>
        <el-button @click="cancel">清空</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "EditUser",
  uid:'',
  data(){
    return{
      form: {
        jid: '',
        username: '',
        password: '',
        truename: '',
        idcardNumber: '',
        authority: '',
        identity: ''
      }
    }
  },
  methods:{
    back: function (){
      this.$router.push("/func/userList");
    },
    upd:function(){
      console.log(this.form);
      this.axios({
        method:"post",
        headers: { 'content-type': 'application/json' },
        url: "http://evidence.frogking.cn/userAdmController/insert",
        params:{
          token:localStorage.getItem("token_only"),
          jid: this.form.jid,
          username : this.form.username,
          password : this.form.password,
          truename : this.form.truename,
          idcardNumber : this.form.idcardNumber,
          authority : this.form.authority,
          identity : this.form.identity
        }
      }).then(res=>{
        if(res["data"]["code"]==='204'){
          this.$router.push('/func/userList')
        }
        else if(res["data"]["code"]==='205'){
          this.$alert('系统错误！添加失败！', '错误提示', {
            confirmButtonText: '确定',
            callback: action => {
                this.form.jid = '',
                this.form.username = '',
                this.form.password = '',
                this.form.truename = '',
                this.form.idcardNumber = '',
                this.form.authority = '',
                this.form.identity = ''
            }
          });
        }
        else if(res["data"]["code"]==='213'){
          this.$alert('身份属性错误！添加异常！', '错误提示', {
            confirmButtonText: '确定',
            callback: action => {
              this.form.jid = '',
                this.form.username = '',
                this.form.password = '',
                this.form.truename = '',
                this.form.idcardNumber = '',
                this.form.authority = '',
                this.form.identity = ''
            }
          });
        }
        else if(res["data"]["code"]==='212'){
          this.$alert('权限属性错误！添加异常！', '错误提示', {
            confirmButtonText: '确定',
            callback: action => {
              this.form.jid = '',
                this.form.username = '',
                this.form.password = '',
                this.form.truename = '',
                this.form.idcardNumber = '',
                this.form.authority = '',
                this.form.identity = ''
            }
          });
        }
        else if(res["data"]["code"]==='211'){
          this.$alert('身份证号格式不匹配！添加异常！', '错误提示', {
            confirmButtonText: '确定',
            callback: action => {
              this.form.jid = '',
                this.form.username = '',
                this.form.password = '',
                this.form.truename = '',
                this.form.idcardNumber = '',
                this.form.authority = '',
                this.form.identity = ''
            }
          });
        }
        else if(res["data"]["code"]==='209'){
          this.$alert('其他属性错误！添加异常！', '错误提示', {
            confirmButtonText: '确定',
            callback: action => {
              this.form.jid = '',
                this.form.username = '',
                this.form.password = '',
                this.form.truename = '',
                this.form.idcardNumber = '',
                this.form.authority = '',
                this.form.identity = ''
            }
          });
        }
        else if(res["data"]["code"]==='000'){
          this.$alert('token失效', '错误提示', {
            confirmButtonText: '确定',
            callback: action => {
              this.$router.push("/login");
              localStorage.removeItem("token_only");
            }
          });
        }
        else if(res["data"]["code"]==='001'){
          this.$alert('token权限不满足，禁止操作', '错误提示', {
            confirmButtonText: '确定'
          });
        }
        else if(res["data"]["code"]==='002'){
          this.$alert('token权限不满足，禁止操作', '错误提示', {
            confirmButtonText: '确定'
          });
        }
      }).catch(function (error) {
        console.log(error);
      });
    },
    cancel:function (){
      this.form.jid = '',
        this.form.username = '',
        this.form.password = '',
        this.form.truename = '',
        this.form.idcardNumber = '',
        this.form.authority = '',
        this.form.identity = ''
    }
  }

}
</script>
<style scoped>

</style>
